<link href="${rc.getContextPath()}/manage/js/businessJs/my_webuploader.css" rel="stylesheet" type="text/css" />
<form method="post" id="editProductionOrder" action="${rc.getContextPath()}/manage/productionOrder/modifyProductionOrder" class="pageForm required-validate" onsubmit="return productionOrderEdit.validForm(this)">
    <div class="pageContent">
    <div class="pageFormContent" layoutH="286">
        <input type="hidden" name="navTabId" value="${navTabId!''}" />
        <fieldset>
        <dl>
            <dt><@label key='productionOrderNum.C,colon'>生产订单编号：</@label></dt>
            <dd><input type="text" name="productionOrderNum" class="required" value="${productionOrder.productionOrderNum!''}" readonly="readonly"/></dd>
        </dl>
        <dl>
            <dt><@label key='orderType.C,colon'>订单类型：</@label></dt>
            <dd><select name="orderTypeCode">
                    <option value="" ><@label key='all.C'>所有</@label></option>
                    <#if orderTypes??>
                        <#list orderTypes as orderType>
                            <option value="${orderType.orderTypeCode!''}" <#if productionOrder.orderTypeCode?? && productionOrder.orderTypeCode == orderType.orderTypeCode> selected</#if> >${orderType.orderTypeText!''}</option>
                        </#list>
                    </#if>
                </select>
            </dd>
        </dl>
        <dl>
            <dt><@label key='orderStatusECode.C,colon'>订单状态：</@label></dt>
            <dd><select name="statuseCode" disabled="disabled">
                    <#if orderStatusECode??>
                        <#list orderStatusECode as ecode>
                            <option value="${ecode.eCode!''}" <#if productionOrder.statuseCode?? && productionOrder.statuseCode == ecode.eCode> selected</#if> >${ecode.eCodeText!''}</option>
                        </#list>
                    </#if>
                </select>
                <input name="statuseCode" type="hidden" value="${productionOrder.statuseCode!''}"/>
            </dd>
            </dd>
        </dl>
        <dl  class="notnormal">
            <dt><@label key='materialCode.C,colon'>物料编号：</@label></dt>
            <dd>
                <input class="required look" id="materialLookup.materialCode" name="materialCode" type="text" postField="materialCode" value="${productionOrder.materialCode!''}" suggestFields="materialCode,materialText" 
                suggestUrl="${rc.getContextPath()}/manage/material/componentSuggest" lookupGroup="materialLookup" callback="productionOrderEdit.setProcessOperationData" remote="${rc.getContextPath()}/manage/material/validateMaterial" warn="<@label key='materialCodeNotExists.M'>物料编号不存在</@label>"/>
                <a class="btnLook" href="${rc.getContextPath()}/manage/material/componentLookUp?lookupType=radio" rel="materialLookup_dialog" title="<@label key='select.C,materialCode.C'>选择物料</@label>" callback="productionOrderEdit.setProcessOperationData" lookupGroup="materialLookup" ></a>
            </dd>
        </dl>
        <dl>
            <dt><@label key='materialText.C,colon'>物料名称：</@label></dt>
            <dd><input id="materialLookup.materialText" name="materialText" type="text" value="${productionOrder.materialText!''}" readonly="readonly"/></dd>
        </dl>
        <dl>
            <dt><@label key='process.C,colon'>工艺：</@label></dt>
            <dd><select id="pp_processCode" name="processCode" class="required">
                    <option value="" ><@label key='select.C'>请选择</@label></option>
                    <#if materiaProcess??>
                        <#list materiaProcess as process>
                            <option value="${process.processCode!''}@_@${process.processRev!''}" <#if productionOrder.processCode?? && productionOrder.processCode == process.processCode> selected</#if> >${process.processText!''}</option>
                        </#list>
                    </#if>
                </select>
            </dd>
        </dl>
        <dl>
            <dt><@label key='cmprocessrev.C,colon'>工艺版本：</@label></dt>
            <dd><input id="pp_processRev" name="processRev" value="${productionOrder.processRev!''}"  readonly />
            </dd>
        </dl>
        <dl>
            <dt><@label key='plannedQuantity.C,colon'>计划数量</@label></dt>
            <dd><input type="text" name="plannedQuantity" value="${productionOrder.plannedQuantity!''}" min="1" maxlength="15" readonly class="required number"/></dd>
        </dl>
        <dl  class="notnormal">
            <dt><@label key='requirementDate.C,colon'>需求日期：</@label></dt>
            <dd><input type="text" name="requirementDate" value="${(productionOrder.requirementDate?string('yyyy-MM-dd'))?if_exists}" readonly class="required date"/>
                <a class="inputDateButton" href="javascript:;">选择</a>
            </dd>
        </dl>
        <dl>
            <dt><@label key='productionlotNum.C,colon'>生产批次号：</@label></dt>
            <dd><input type="text" name="productionlotNum" value="${productionOrder.productionlotNum!''}" maxlength="40"/></dd>
        </dl>
        <dl  class="notnormal">
            <dt><@label key='plannedstartDateTime.C,colon'>计划开始时间：</@label></dt>
            <dd><input type="text" name="plannedstartDateTime" class="required date" max_Date="{plannedendDateTime}" readonly value="${(productionOrder.plannedstartDateTime?string('yyyy-MM-dd HH:mm:ss'))?if_exists}"
            max_date="plannedendDateTime" dateFmt="yyyy-MM-dd HH:mm:ss" />
            <a class="inputDateButton" href="javascript:;">选择</a>
            </dd>
        </dl>
        <dl  class="notnormal">
            <dt><@label key='plannedendDateTime.C,colon'>计划结束时间：</@label></dt>
            <dd><input type="text" name="plannedendDateTime" class="required date" min_Date="{plannedstartDateTime}" readonly value="${(productionOrder.plannedendDateTime?string('yyyy-MM-dd HH:mm:ss'))?if_exists}"
            min_date="plannedstartDateTime" dateFmt="yyyy-MM-dd HH:mm:ss"/>
            <a class="inputDateButton" href="javascript:;">选择</a>
            </dd>
        </dl>
        <dl>
            <dt><@label key='customer.C,colon'>客户：</@label></dt>
            <dd><input type="text" name="customer"  value="${productionOrder.customer!''}"/></dd>
        </dl>
        <dl>
            <dt><@label key='customerOrder.C,colon'>客户订单：</@label></dt>
            <dd><input type="text" name="customerOrder"  value="${productionOrder.customerOrder!''}"/></dd>
        </dl>
         <dl>
            <dt><@label key='priority.C,colon'>优先级：</@label></dt>
            <dd><input type="text" name="priority" class="digits" maxlength="5" value="${productionOrder.priority!''}"/></dd>
        </dl>
        <dl>
            <dd><span style="color:red" id="processMsgInfo"></span></dd>
        </dl>
        </fieldset>
    </div>
    <div class="tabs">
        <div class="tabsHeader">
            <div class="tabsHeaderContent">
                <ul><li id="attachment" data-selectedid="productionOrder_attachment" class="exerInputS"><a href="javascript:;" id="select1"><span><@label key='attachment.C'>附件</@label></span></a></li></ul>
            </div>
        </div>
        <div class="tabsContent" style="border-bottom: 1px #d8dfe5 solid;height:200px">
            <div>
                <div class="pageHeader">
                    <div id="uploader" class="wu-example">
                        <!--用来存放文件信息-->
                        <div id="filelist" class="uploader-list"></div>
                    </div>
                    <div id="processFile" class="choose-file" uploaderOption="{
                                    server:'${rc.getContextPath()}/manage/process/saveProcessAttachment',
                                    fileVal:'productionOrderfile',
                                    fileBnt: 'fileBnt',
                                    fileList: 'filelist',
                                    beforeFileQueuedMsg: '<@label key='exeBat_type_msg.D'>请不要上传exe，bat，sh等可执行的文件</@label>',
                                    uploadSuccess: productionOrderEdit._addProductionAttachment
                                }"><@label key='chooseFile.C'>选择文件</@label></div>
                    <div class="buttonActive" style="float: right;">
                        <div class="buttonContent"><button id="fileBnt" type="button"><@label key='upload.B'>上传</@label></button></div>
                    </div>
                </div>
                <table class="table canopration border" style="width: 100%;" id="productionAttachMentTable">
                    <thead>
                        <tr>
                            <th width="100px"><@label key='fileName.C'>文件名称</@label></th>
                            <th width="100px"><@label key='fileSize.C'>文件大小(bytes)</@label></th>
                            <th width="50px"><@label key="opera.C">操作</@label></th>
                        </tr>
                    </thead>
                    <tbody>
                        <#if productionOrder?? && productionOrder.attachment??>
                        <#list productionOrder.attachment as attachment>
                            <tr id="productionAttachment_${attachment.id!''}">
                                <td>${attachment.fileName!''} <input type="hidden" name="attachment[${attachment_index}].fileName" value="${attachment.fileName!''}"/></td>
                                <td>${(attachment.fileSize/1024)?int} kb<input type="hidden" name="attachment[${attachment_index}].attachmentCode" value="${attachment.attachmentCode!''}"/></td>
                                <td>
                                    <a title="<@label key='delete.B'>删除</@label>" target="ajax" class="btnDel" onclick="productionOrderEdit._delProductionAttachment('productionAttachment_${attachment.id!''}');"><@label key="delete.B">删除</@label></a>
                                    <a title="<@label key='download.B'>下载</@label>" target="dwzExport" class="btnAttach" href="${rc.getContextPath()}/manage/common/downloadAttachement?attachmentCode=${attachment.attachmentCode!''}&fileName=${attachment.fileName!''}"></a>
                                </td>
                            </tr>
                        </#list>
                    </#if>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="formBar">
        <ul>
            <li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
            <li>
                <div class="buttonActiveGrey"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
            </li>
        </ul>
    </div>
    </div>
</form>
<script type="text/javascript">
    var productionOrderEdit = {
            editProductionOrderDialog : $.pdialog.getCurrent(),
            productionAttachmentCount : 0,
            setProcessOperationData : function(){
                 var materialCode =  $("input[name='materialCode']", productionOrderEdit.editProductionOrderDialog).val();
                    if(materialCode && materialCode!=""){
                        $("select#pp_processCode").html("");
                        $.DWZajax({
                            url:hostUrl +"/productionOrder/getProcessByMaterial",
                            data:{'materialCode':materialCode},
                            callback:function(data){
                                if(data && data.length > 0){
                                	$("input#pp_processRev", productionOrderEdit.currentDialog).val("");
                                    var options = "<option value='' ><@label key='select.C'>请选择</@label></option>";
                                    for(var i=0; i<data.length; i++){
                                        if(data[i].isDefault == 1) {//默认工艺默认选择 
                                            options += "<option selected value="+data[i].processCode+"@_@"+data[i].processRev+">"+data[i].processText+"</option>";
                                            //2016-10-26 YJL新增工艺版本赋值
                                            $("input#pp_processRev", productionOrderEdit.currentDialog).val(data[i].processRev);
                                        }else{
                                            options += "<option value="+data[i].processCode+"@_@"+data[i].processRev+">"+data[i].processText+"</option>";
                                        }
                                    }
                                    $("select#pp_processCode",productionOrderEdit.editProductionOrderDialog).html(options);
                                    $("span#processMsgInfo", productionOrderEdit.editProductionOrderDialog).html("");
                                }else{
                                    $("select#pp_processCode", productionOrderEdit.editProductionOrderDialog).html("");
                                    $("span#processMsgInfo", productionOrderEdit.editProductionOrderDialog).html("<@label key='material_noProcess.M'>此物料没有相应的工艺，请从新选择</@label>");
                                    //alertMsg.info("此物料没有相应的工艺，请从新选择!");
                                }
                            }
                        });
                    }
            },
           _addProductionAttachment : function(data){
               if(!data)
                   return;
               productionOrderEdit.productionAttachmentCount ++ ;
               var gridTheadTh = $("#productionAttachMentTable", $.pdialog.getCurrent()).find("table thead th");
               var _id = "productionAttachment_"+productionOrderEdit.productionAttachmentCount;
               var tr = "<tr id="+_id+">";
               tr += "<td style='width:"+$(gridTheadTh[0]).width()+"px'><div>"+data.fileName+"</div><input type='hidden' name='attachment["+productionOrderEdit.productionAttachmentCount+"].fileName' value='"+data.fileName+"'/></td>";
               tr += "<td style='width:"+$(gridTheadTh[1]).width()+"px'><div>"+Math.round(data.fileSize/1024)+"kb</div><input type='hidden' name='attachment["+productionOrderEdit.productionAttachmentCount+"].attachmentCode' value='"+data.attachmentCode+"'/></td>";
               tr += "<td style='width:"+$(gridTheadTh[2]).width()+"px'><a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='productionOrderEdit._delProductionAttachment(\""+_id+"\");'><@label key='delete.B'>删除</@label></a>";
               tr += "<a title='<@label key='download.B'>下载</@label>' target='dwzExport' class='btnAttach' href='${rc.getContextPath()}/manage/common/downloadAttachement?attachmentCode="+data.attachmentCode+"&fileName="+data.fileName+"'></a></td>"
               tr += "</tr>";
               $("#productionAttachMentTable .gridTbody", productionOrderEdit.editProductionOrderDialog).find("table tbody").append(tr);
           },
           _delProductionAttachment : function(_id){
               if(_id && _id!="")
                   $("tr#"+_id, $.pdialog.getCurrent()).remove();
           }, 
           //2016-10-26 YJL 新增表单验证方法，判断计划结束时间是否大于需求时间，若大于则提示用户是否继续操作
           validForm : function(form){
               var planEndDate  = $("input[name='plannedendDateTime']",$(form)).val().substring(0,10);
               var requiredDate = $("input[name='requirementDate']",$(form)).val();
               if(planEndDate > requiredDate){
                   alertMsg.confirm("<@label key='confirmPlanEndDateLaterThanRequiredDate.M'>当前计划结束时间晚于需求时间，是否继续？</@label>",{
                       okCall : function(){
                           return validateCallback(form, dialogAjaxDone);
                       },
                       cancelCall : function(){
                           return false;
                       }
                   })
                   return false;
               }else{
                   return validateCallback(form, dialogAjaxDone)
               }
           }
    }
    
    $(function(){
        //2016-10-26 YJL 给工艺下拉框初始化监听事件，当工艺选择改变时联动刷新工艺版本信息
        $("select#pp_processCode", productionOrderEdit.currentDialog).on("change",function(){
            var value = $(this).val();
            if(value && "" !== value){
                $("input#pp_processRev", productionOrderEdit.currentDialog).val(value.split("@_@")[1]||"");
            }else{
                $("input#pp_processRev", productionOrderEdit.currentDialog).val("");
            }
        });
        <#if processOperation?? && processOperation.component?size gt 0>
           productionOrderEdit.productionAttachmentCount = ${productionOrder.attachment.size};        
        </#if>
    })
</script>
<script type="text/javascript" src="${rc.getContextPath()}/manage/js/businessJs/my_webuploader.js"></script>
